package net.domor.stock.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

@Controller
@RequestMapping("demo")
public class DemoController {
    @RequestMapping("/upload")
    public String upload(HttpServletRequest request,
                         @RequestParam("file") MultipartFile file) throws Exception {
        if (!file.isEmpty()) {
            file.transferTo(new File("F:/" + file.getOriginalFilename()));
            request.setAttribute("info", "上传成功！");
        } else {
            request.setAttribute("info", "上传失败！");
        }
        return "message";
    }
}
